home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1998 August / macformat-066.iso / How-to's / Foreign Files / Creator Changer 2.8.4 / Code & Resource / Creator Changer.dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  30.3 KB  |  1,070 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file contains the bulk of the program.  All of the dialog box
  3.  *    stuff is performed in this file.
  4.  **********************************************************************/
  5.  
  6. #include    "Creator Changer.h"
  7. #include    "Creator Changer.dialog.h"
  8.  
  9.  
  10. /**********************************************************************
  11.  *    Function Open_DLOG(), this function is a general function for 
  12.  *    opening all of the Dialog boxes in the program.
  13.  **********************************************************************/
  14.  
  15. void Open_DLOG(Dialog_Info *the)
  16.     {
  17.  
  18.     Handle    item_handle;
  19.     
  20.     if(proc_for_draw_Chng_dialog==NIL_PTR) proc_for_draw_Chng_dialog=NewUserItemProc(Draw_Chng_Dialog);
  21.     if(proc_for_draw_Pref_dialog==NIL_PTR) proc_for_draw_Pref_dialog=NewUserItemProc(Draw_Pref_Dialog);
  22.     if(proc_for_draw_Abot_dialog==NIL_PTR) proc_for_draw_Abot_dialog=NewUserItemProc(Draw_Abot_Dialog);
  23.     
  24.     if(Has_Drag_Mgr)
  25.         {
  26.         if(drag_tracking==NIL_PTR) drag_tracking=NewDragTrackingHandlerProc(Handle_Drag_Tracking);
  27.         if(drag_receiver==NIL_PTR) drag_receiver=NewDragReceiveHandlerProc(Handle_Drag_Receive_Drop);
  28.         }
  29.     
  30.     the->dialog=GetNewDialog(the->dlog_id, the->storage, IN_FRONT);
  31.     
  32.     if(the->dialog==Chng.dialog)
  33.         {
  34.         Make_Pop_Up_Menu(the->menu_id, the->pref_type, the->num_items);
  35.         Set_Dialog_Proc((Handle)proc_for_draw_Chng_dialog, Chng.dialog, CHNG_DLOG_UI);
  36.         if(!Multiple_Files)
  37.             {
  38.             Set_Type_Text(F_Type, File_Info.fdType);
  39.             Set_Type_Text(C_Type, File_Info.fdCreator);
  40.             }
  41.         if(Has_Drag_Mgr)
  42.             {
  43.             InstallTrackingHandler(drag_tracking, Chng.dialog, (void *)NIL_PTR);
  44.             InstallReceiveHandler(drag_receiver, Chng.dialog, (void *)NIL_PTR);
  45.             }
  46.         }
  47.     else if(the->dialog==About.dialog) Set_Dialog_Proc((Handle)proc_for_draw_Abot_dialog, About.dialog, ABOUT_DLOG_UI);
  48.     else if(the->dialog==Pref.dialog)
  49.         {
  50.         Get_Dialog_Item_Hndl(the->dialog, PREF_POPUP, &item_handle);
  51.         Handle_Pref_Pop_Up_Menu(the, YES);
  52.         
  53.         if(Has_Drag_Mgr)
  54.             {
  55.             InstallTrackingHandler(drag_tracking, Pref.dialog, (void *)NIL_PTR);
  56.             InstallReceiveHandler(drag_receiver, Pref.dialog, (void *)NIL_PTR);
  57.             }
  58.  
  59.         }
  60.     Maintain_Menu_Items(FrontWindow());
  61.  
  62.     }
  63.  
  64.  
  65.  
  66. /**********************************************************************
  67.  *    Function Switch_Chng_Dialog(), this function decides where events
  68.  *    in the Change Dialog box should go.
  69.  **********************************************************************/
  70.  
  71. void Switch_Chng_Dialog(Dialog_Info *the, short item_hit)
  72.     {
  73.     
  74.     switch(item_hit)
  75.         {
  76.         case CHNG_OK:
  77.             Handle_Chng_OK(the->dialog, &the->files, the->num_files, CHNG_CREATOR, CHNG_FILE);
  78.             break;
  79.         case CHNG_POP_UP:
  80.             Handle_Pt_Pop_Up(the->dialog, CHNG_POP_UP, CHNG_CREATOR, CHNG_FILE, NO);
  81.             break;
  82.         case CHNG_CANCEL:
  83.             if(Has_Drag_Mgr)
  84.                 {
  85.                 RemoveTrackingHandler(drag_tracking, the->dialog);
  86.                 RemoveReceiveHandler(drag_receiver, the->dialog);
  87.                 }
  88.             CloseDialog(the->dialog);
  89.             Done_With_Dialog=YES;
  90.             Maintain_Menu_Items(FrontWindow());
  91.             break;
  92.         case CHNG_MKLK:
  93.             Handle_Make_Like(the->dialog, CHNG_FILE, CHNG_CREATOR, NIL_PTR);
  94.             break;
  95.         case CHNG_CRNT_CREATOR:
  96.             if(!Multiple_Files) Set_DLOG_Text_Item(the->dialog, CHNG_CREATOR, C_Type);
  97.             break;
  98.         case CHNG_CRNT_TYPE:
  99.             if(!Multiple_Files) Set_DLOG_Text_Item(the->dialog, CHNG_FILE, F_Type);
  100.             break;
  101.         }
  102.         
  103.     }
  104.  
  105.  
  106. /**********************************************************************
  107.  *    Function Switch_Pt_Dialog(), this function decides where events
  108.  *    in the Edit DITL should go.  This is part of the Preference Dialog.
  109.  **********************************************************************/
  110.  
  111. void Switch_Pt_Dialog(Dialog_Info *the, short item_hit)
  112.     {
  113.     
  114.     short            os=the->num_items;
  115.     
  116.     switch(item_hit-os)
  117.         {
  118.         case P_PT_PM:
  119.             Handle_Pt_Pop_Up(the->dialog, os+P_PT_PM, os+P_PT_CT, os+P_PT_FT, os+P_PT_DS);
  120.             break;
  121.         case P_PT_ADD:
  122.             Handle_Pt_Add_Item(the->dialog, os+P_PT_CT, os+P_PT_FT, os+P_PT_DS);
  123.             break;
  124.         case P_PT_DEL:
  125.             Handle_Pt_Del_Item();
  126.             break;
  127.         case P_PT_GFL:
  128.             Handle_Make_Like(the->dialog, os+P_PT_FT, os+P_PT_CT, NIL_PTR);
  129.             break;
  130.         }
  131.         
  132.     }
  133.  
  134.  
  135. /**********************************************************************
  136.  *    Function Switch_Ac_Dialog(), this function decides where events
  137.  *    in the Auto DITL should go.  This is part of the Preference Dialog.
  138.  **********************************************************************/
  139.  
  140. void Switch_Ac_Dialog(Dialog_Info *the, short item_hit)
  141.     {
  142.     
  143.     short            os=the->num_items;
  144.     
  145.     switch(item_hit-os)
  146.         {
  147.         case P_AC_POPM:
  148.             Handle_Ac_Pop_Up(the->dialog, os+P_AC_POPM, os+P_AC_CHFT, os+P_AC_CTCT, os+P_AC_CTFT);
  149.             break;
  150.         case P_AC_ADD:
  151.             Handle_Ac_Add_Item(the->dialog, os+P_AC_CHFT, os+P_AC_CTCT, os+P_AC_CTFT);
  152.             break;
  153.         case P_AC_DEL:
  154.             Handle_Ac_Del_Item();
  155.             break;
  156.         case P_AC_GFL:
  157.             Handle_Make_Like(the->dialog, os+P_AC_CTFT, os+P_AC_CTCT, os+P_AC_CHFT);
  158.             break;
  159.         }
  160.         
  161.     }
  162.  
  163.  
  164. /**********************************************************************
  165.  *    Function Switch_Abot_Dialog(), this function decides where events
  166.  *    in the About Dialog should go. 
  167.  **********************************************************************/
  168.  
  169. void Switch_Abot_Dialog(Dialog_Info *the, short item_hit)
  170.     {
  171.     
  172.     switch(item_hit)
  173.         {
  174.         case ABOUT_OK:
  175.             CloseDialog(the->dialog);
  176.             Maintain_Menu_Items(FrontWindow());
  177.             break;
  178.         }
  179.         
  180.     }
  181.  
  182.  
  183. /**********************************************************************
  184.  *    Function Switch_Pref_Dialog(), this function decides where events
  185.  *    in the Preference Dialog box should go.
  186.  **********************************************************************/
  187.  
  188. void Switch_Pref_Dialog(Dialog_Info *the, short item_hit)
  189.     {
  190.     
  191.     switch(item_hit)
  192.         {
  193.         case PREF_POPUP:
  194.             Handle_Pref_Pop_Up_Menu(the, NO);
  195.             break;
  196.         case PREF_DONE:
  197.             if(Has_Drag_Mgr)
  198.                 {
  199.                 RemoveTrackingHandler(drag_tracking, the->dialog);
  200.                 RemoveReceiveHandler(drag_receiver, the->dialog);
  201.                 }
  202.             CloseDialog(the->dialog);
  203.             the->menu_id=NIL_PTR;
  204.             Maintain_Menu_Items(FrontWindow());
  205.         default:
  206.             Handle_Pref_DITL_Item(the, item_hit);
  207.             break;
  208.         }
  209.         
  210.     }
  211.  
  212.  
  213.  
  214. /**********************************************************************
  215.  *    Function Switch_Gnrl_Dialog(), this function decides where events
  216.  *    in the General DITL should go.  This is part of the Preference Dialog.
  217.  **********************************************************************/
  218.  
  219. void Switch_Gnrl_Dialog(Dialog_Info *the, short item_hit)
  220.     {
  221.     
  222.     short            os=the->num_items;
  223.     
  224.     switch(item_hit-os)
  225.         {
  226.         case P_GN_OKAC:
  227.             UseResFile(CreatorChangerPref);
  228.                 (**Global).AutoChange=Handle_Check_Item(the->dialog, os+P_GN_OKAC);
  229.                 ChangedResource((Handle)Global);
  230.                 UpdateResFile(CreatorChangerPref);
  231.             UseResFile(CreatorChangerApp);
  232.             break;
  233.         case P_GN_QADD:
  234.             UseResFile(CreatorChangerPref);
  235.                 (**Global).DragQuit=Handle_Check_Item(the->dialog, os+P_GN_QADD);
  236.                 ChangedResource((Handle)Global);
  237.                 UpdateResFile(CreatorChangerPref);
  238.             UseResFile(CreatorChangerApp);
  239.             break;
  240.         }
  241.         
  242.     }
  243.  
  244.  
  245. /**********************************************************************
  246.  *    Function Handle_Chng_OK(), this function changes the file and 
  247.  *    creator types of the file(s) opened.
  248.  **********************************************************************/
  249.  
  250. void Handle_Chng_OK(DialogRef the_dialog, AEDescList *the_files, long num_of_files, short creator, short file)
  251.      {
  252.      
  253.      short    register    i;
  254.      short                 temp;
  255.      AEKeyword            key_word;
  256.     DescType            the_type;
  257.     Size                the_size;
  258.     Str4                the_text;
  259.      
  260.      temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO);
  261.      
  262.     if(temp<TYPE_LEN)
  263.         {
  264.         for(i=1;i<=num_of_files;i++)
  265.             {
  266.             if(Multiple_Files)
  267.                 {
  268.                 AEGetNthPtr(the_files, i, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
  269.                 FSpGetFInfo(&The_File_Spec, &File_Info);
  270.                 }
  271.             Get_Dialog_Text(the_text, the_dialog, CHNG_FILE);
  272.             Set_Type_Long(the_text, &File_Info.fdType,    the_dialog, file);
  273.             Get_Dialog_Text(the_text, the_dialog, CHNG_CREATOR);
  274.             Set_Type_Long(the_text, &File_Info.fdCreator, the_dialog, creator);
  275.             FSpSetFInfo(&The_File_Spec, &File_Info);
  276.             }
  277.         Force_Finder_Update(&The_File_Spec);
  278.         if(Multiple_Files) AEDisposeDesc(the_files);
  279.         CloseDialog(the_dialog);
  280.         Maintain_Menu_Items(FrontWindow());
  281.         Done_With_Dialog=YES;
  282.         }
  283.     else Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
  284.     
  285.     }
  286.  
  287.  
  288.  
  289. /**********************************************************************
  290.  *    Function Set_Type_Long(), this function converts a string in an  
  291.  *    edit field to an OStype.
  292.  **********************************************************************/
  293.  
  294. void Set_Type_Long(Str4 in_the_text_type, OSType *out_the_ostype,  DialogRef the_dialog, short ID)
  295.     {
  296.     
  297.     register short        i;
  298.     Byte                *temp;
  299.     
  300.     temp=(Byte *)out_the_ostype;
  301.     
  302.     for(i=0;i<TYPE_LEN;++i) temp[i]=in_the_text_type[i+1];
  303.     
  304.     }
  305.  
  306.  
  307.  
  308. /**********************************************************************
  309.  *    Function Set_Type_Text(), this function sets the text for the file
  310.  *    and creator types given an usigned decimal file / creator type.
  311.  **********************************************************************/
  312.  
  313. void Set_Type_Text(Str4 out_the_text_type, OSType in_the_ostype)
  314.     {
  315.     
  316.     register short        i;
  317.     Byte                *temp;
  318.     
  319.     out_the_text_type[0]=TYPE_LEN;
  320.     
  321.     temp=(Byte *)&in_the_ostype;
  322.     for(i=0;i<TYPE_LEN;++i) out_the_text_type[i+1]=temp[i];
  323.     
  324.     }
  325.  
  326.  
  327.  
  328. /**********************************************************************
  329.  *    Function Handle_Make_Like(), this function picks a file to use as
  330.  *    a template.
  331.  **********************************************************************/
  332.  
  333. void Handle_Make_Like(DialogRef the_dialog, short file, short creator, short from_file)
  334.     {
  335.     
  336.     Str4        f_type, c_type;
  337.     FSSpec        ml_file_spec;
  338.     FInfo        ml_file_info;
  339.     
  340.     if(Pick_File(&ml_file_spec, &ml_file_info, FALSE))
  341.         {
  342.         Set_Type_Text(f_type, ml_file_info.fdType);
  343.         Set_Type_Text(c_type, ml_file_info.fdCreator);
  344.         
  345.         if(from_file) Set_DLOG_Text_Item(the_dialog, from_file, f_type);
  346.         Set_DLOG_Text_Item(the_dialog, file,    f_type);
  347.         Set_DLOG_Text_Item(the_dialog, creator, c_type);
  348.         }
  349.     PT_Item_To_Edit=AC_Item_To_Edit=0;
  350.     
  351.     }
  352.  
  353.  
  354.  
  355. /**********************************************************************
  356.  *    Function Handle_Pt_Add_Item(), this function actually does the adding
  357.  *    of the items to the preferences file.
  358.  **********************************************************************/
  359.  
  360. void Handle_Pt_Add_Item(DialogRef the_dialog, short creator, short file, short description)
  361.     {
  362.     
  363.     short        temp;
  364.     pref_types    **rsrc_handle;
  365.     
  366.     temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO)+Check_Data(the_dialog, description, YES);
  367.     
  368.     if(temp<TYPE_LEN)
  369.         {
  370.         UseResFile(CreatorChangerPref);
  371.             rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
  372.             
  373.             Get_Dialog_Text((**rsrc_handle).Description, the_dialog, description);
  374.             Get_Dialog_Text((**rsrc_handle).CreatorType, the_dialog, creator);
  375.             Get_Dialog_Text((**rsrc_handle).FileType, the_dialog, file);
  376.             
  377.             AddResource((Handle)rsrc_handle, PREF_PT, Chng.num_items==0 ? Strt_Rsrc : The_pt_Type[Chng.num_items]+1, (**rsrc_handle).Description);
  378.             ChangedResource((Handle)rsrc_handle);
  379.             UpdateResFile(CreatorChangerPref);
  380.             Chng.num_items=Edit.num_items=CountResources(PREF_PT);
  381.             ReleaseResource((Handle)rsrc_handle);
  382.         UseResFile(CreatorChangerApp);
  383.         Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Chng.num_items);
  384.         PT_Item_To_Edit=0;
  385.         }
  386.     else if(temp<=TYPE_LEN+TYPE_LEN+1)    Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
  387.     else if(temp==DESC_LEN+2)            Do_Error(Descr_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  388.     else                                Do_Error(Types_Error_1, Descr_Error, EMPTY_STR, EMPTY_STR);
  389.     
  390.     }
  391.  
  392.  
  393.  
  394. /**********************************************************************
  395.  *    Function Handle_Pt_Del_Item(), this function actually does the
  396.  *    deleting of the item from the preferences file.
  397.  **********************************************************************/
  398.  
  399. void Handle_Pt_Del_Item(void)
  400.     {
  401.     
  402.     short        resource_number, i;
  403.     pref_types    **rsrc_handle;
  404.     
  405.     if(PT_Item_To_Edit)
  406.         {
  407.         UseResFile(CreatorChangerPref);
  408.             resource_number=The_pt_Type[PT_Item_To_Edit];
  409.             rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
  410.             rsrc_handle=(pref_types **)GetResource(PREF_PT, resource_number);
  411.             RemoveResource((Handle)rsrc_handle);
  412.             ReleaseResource((Handle)rsrc_handle);
  413.             UpdateResFile(CreatorChangerPref);
  414.             for(i=(resource_number+1);i<=The_pt_Type[Chng.num_items];i++)
  415.                 {
  416.                 rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
  417.                 DetachResource((Handle)rsrc_handle);
  418.                 AddResource((Handle)rsrc_handle, PREF_PT, i-1, NIL_PTR);
  419.                 ChangedResource((Handle)rsrc_handle);
  420.                 ReleaseResource((Handle)rsrc_handle);
  421.                 
  422.                 rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
  423.                 RemoveResource((Handle)rsrc_handle);
  424.                 ChangedResource((Handle)rsrc_handle);
  425.                 ReleaseResource((Handle)rsrc_handle);
  426.                 }
  427.             UpdateResFile(CreatorChangerPref);
  428.             Chng.num_items=Edit.num_items=CountResources(PREF_PT);
  429.         UseResFile(CreatorChangerApp);
  430.         Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Chng.num_items);
  431.         PT_Item_To_Edit=0;
  432.         }
  433.     else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  434.         
  435.     }
  436.  
  437.  
  438.  
  439. /**********************************************************************
  440.  *    Function Handle_Ac_Add_Item(), this function actually does the adding
  441.  *    of the items to the preferences file.
  442.  **********************************************************************/
  443.  
  444. void Handle_Ac_Add_Item(DialogRef the_dialog, short from_file_id, short to_creator_id, short to_file_id)
  445.     {
  446.     
  447.     OSType        long_from_file;
  448.     short        temp;
  449.     auto_chng    **rsrc_handle;
  450.     Str4        types[100];
  451.                 
  452.     temp=Check_Data(the_dialog, from_file_id, NO)+Check_Data(the_dialog, to_creator_id, NO)+Check_Data(the_dialog, to_file_id, NO);
  453.     
  454.     if(temp<TYPE_LEN)
  455.         {
  456.         Get_Types_From_Prefs(types);
  457.         Set_Type_Long(NIL_PTR, &long_from_file, the_dialog, from_file_id);
  458.         if(Check_File_Type(types, long_from_file)) Do_Error(Bad_CF_Type_1, Bad_CF_Type_2, Bad_CF_Type_3, Bad_CF_Type_4);
  459.         else
  460.             {
  461.             rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
  462.             
  463.             Get_Dialog_Text((**rsrc_handle).FromFile, the_dialog, from_file_id);
  464.             Get_Dialog_Text((**rsrc_handle).ToCreator, the_dialog, to_creator_id);
  465.             Get_Dialog_Text((**rsrc_handle).ToFile, the_dialog, to_file_id);
  466.             
  467.             Make_Ac_Name((**rsrc_handle).Name, (**rsrc_handle).FromFile, (**rsrc_handle).ToCreator, (**rsrc_handle).ToFile);
  468.             UseResFile(CreatorChangerPref);
  469.                 AddResource((Handle)rsrc_handle, PREF_AC, Auto.num_items==0 ? Strt_Rsrc : The_ac_Type[Auto.num_items]+1, (**rsrc_handle).Name);
  470.                 ChangedResource((Handle)rsrc_handle);
  471.                 UpdateResFile(CreatorChangerPref);
  472.                 Auto.num_items=CountResources(PREF_AC);
  473.             UseResFile(CreatorChangerApp);
  474.             ReleaseResource((Handle)rsrc_handle);
  475.             }
  476.         Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Auto.num_items);
  477.         AC_Item_To_Edit=0;
  478.         }
  479.     else Do_Error(Types_Error_1, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  480.     
  481.     }
  482.  
  483.  
  484.  
  485. /**********************************************************************
  486.  *    Function Make_Ac_Name(), this function makes the name
  487.  *    which shows up in the pop-up menu for the auto change items.
  488.  **********************************************************************/
  489.  
  490. void Make_Ac_Name(StringPtr name, StringPtr from_file, StringPtr to_creator, StringPtr to_file)
  491.     {
  492.     
  493.     register short i;
  494.     
  495.     name[0]=16;
  496.     for(i=1;i<=4;i++) name[i]=from_file[i];
  497.     name[5]='-';
  498.     name[6]='>';
  499.     for(i=7;i<=10;i++) name[i]=to_creator[i-6];
  500.     name[11]=',';
  501.     name[12]=' ';
  502.     for(i=13;i<=16;i++) name[i]=to_file[i-12];
  503.     
  504.     }
  505.  
  506.  
  507. /**********************************************************************
  508.  *    Function Handle_Ac_Del_Item(), this function deletes items 
  509.  *    from the auto change item list.
  510.  **********************************************************************/
  511.  
  512. void Handle_Ac_Del_Item(void)
  513.     {
  514.     
  515.     short        resource_number, i;
  516.     auto_chng    **rsrc_handle;
  517.     
  518.     if(AC_Item_To_Edit)
  519.         {
  520.         UseResFile(CreatorChangerPref);
  521.             resource_number=The_ac_Type[AC_Item_To_Edit];
  522.             rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
  523.             rsrc_handle=(auto_chng **)GetResource(PREF_AC, resource_number);
  524.             RemoveResource((Handle)rsrc_handle);
  525.             ReleaseResource((Handle)rsrc_handle);
  526.             UpdateResFile(CreatorChangerPref);
  527.             for(i=(resource_number+1);i<=The_ac_Type[Auto.num_items];i++)
  528.                 {
  529.                 rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
  530.                 DetachResource((Handle)rsrc_handle);
  531.                 AddResource((Handle)rsrc_handle, PREF_AC, i-1, NIL_PTR);
  532.                 ChangedResource((Handle)rsrc_handle);
  533.                 ReleaseResource((Handle)rsrc_handle);
  534.                 
  535.                 rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
  536.                 RemoveResource((Handle)rsrc_handle);
  537.                 ChangedResource((Handle)rsrc_handle);
  538.                 ReleaseResource((Handle)rsrc_handle);
  539.                 }
  540.             UpdateResFile(CreatorChangerPref);
  541.             Auto.num_items=CountResources(PREF_AC);
  542.         UseResFile(CreatorChangerApp);
  543.         Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Auto.num_items);
  544.         AC_Item_To_Edit=0;
  545.         }
  546.     else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  547.     
  548.     }
  549.  
  550.  
  551. /**********************************************************************
  552.  *    Function Handle_Check_Item(), this function either checks or 
  553.  *    unchecks a check box item.
  554.  **********************************************************************/
  555.  
  556. Boolean Handle_Check_Item(DialogRef the_dialog, short dialog_item)
  557.     {
  558.     
  559.     Boolean        value;
  560.     Handle        the_handle;
  561.     
  562.     Get_Dialog_Item_Hndl(the_dialog, dialog_item, &the_handle);
  563.     value=GetControlValue((ControlHandle)the_handle);
  564.     
  565.     if(value==TRUE)
  566.         {
  567.         SetControlValue((ControlHandle)the_handle, FALSE);
  568.         return(FALSE);
  569.         }
  570.     else if(value==FALSE)
  571.         {
  572.         SetControlValue((ControlHandle)the_handle, TRUE);
  573.         return(TRUE);
  574.         }
  575.     
  576.     }
  577.  
  578.  
  579. /**********************************************************************
  580.  *    Function Draw_Default_Border(), this function draws the border
  581.  *    around the item sent to it, that is within the specified dialog box
  582.  **********************************************************************/
  583.  
  584. void Draw_Border(DialogRef the_dialog, short the_item, short is_default)
  585.     {
  586.     
  587.     short        diameter;
  588.     Rect        item_rect;
  589.     GrafPtr        old_port;
  590.     
  591.     GetPort(&old_port);
  592.     SetPort(the_dialog);
  593.     
  594.     Get_Dialog_Item_Rect(the_dialog, the_item, &item_rect);
  595.     if(is_default)
  596.         {
  597.         diameter=(item_rect.bottom-item_rect.top)/2+6;
  598.         if(diameter<16) diameter=16;
  599.         PenSize(3, 3);
  600.         InsetRect(&item_rect, -4, -4);
  601.         FrameRoundRect(&item_rect, diameter, diameter);
  602.         }
  603.     else
  604.         {
  605.         PenSize(1, 1);
  606.         FrameRect(&item_rect);
  607.         }
  608.         
  609.     SetPort(old_port);
  610.     
  611.     }
  612.  
  613.  
  614.  
  615. /**********************************************************************
  616.  *    Function Draw_Chng_Crnt_Type(), this function handels what happens 
  617.  *    if a key is pressed.
  618.  **********************************************************************/
  619.  
  620. void Draw_Chng_Crnt_Type(DialogRef the_dialog)
  621.     {
  622.     
  623.     Rect    item_rect;
  624.     GrafPtr    old_port;
  625.     
  626.     TextFont(systemFont);
  627.     TextSize(12);
  628.     TextFace(0);
  629.     
  630.     GetPort(&old_port);
  631.     SetPort(the_dialog);
  632.     
  633.     Draw_Border(the_dialog, CHNG_CRNT_CREATOR, NO);
  634.     Get_Dialog_Item_Rect(the_dialog, CHNG_CRNT_CREATOR, &item_rect);
  635.     MoveTo(item_rect.left+4, item_rect.bottom-7);
  636.     DrawString(C_Type);
  637.     
  638.     Draw_Border(the_dialog, CHNG_CRNT_TYPE, NO);
  639.     Get_Dialog_Item_Rect(the_dialog, CHNG_CRNT_TYPE, &item_rect);
  640.     MoveTo(item_rect.left+4, item_rect.bottom-7);
  641.     DrawString(F_Type);
  642.     
  643.     SetPort(old_port);
  644.     
  645.     }
  646.  
  647.  
  648.  
  649. /**********************************************************************
  650.  *    Function Check_Data(), this function checks the type entered
  651.  *    by the user.  If there are more than 4 charachters than there is 
  652.  *    an error, and if there is no data entered in there is an error.
  653.  **********************************************************************/
  654.  
  655. short Check_Data(DialogRef the_dialog, short ID, short is_desc)
  656.     {
  657.     
  658.     Str255        the_error;
  659.     short        the_type_len, len;
  660.     Str32        item_text;
  661.     
  662.     Get_Dialog_Text(item_text, the_dialog, ID);
  663.     len=item_text[0];
  664.     if(is_desc) the_type_len=DESC_LEN;
  665.     else the_type_len=TYPE_LEN;
  666.     if(len!=the_type_len && the_type_len==TYPE_LEN) return(TYPE_LEN);
  667.     else if((len>the_type_len && the_type_len==DESC_LEN) || len==0) return(DESC_LEN);
  668.     else return(GOOD);
  669.     
  670.     }
  671.  
  672.  
  673.  
  674. /**********************************************************************
  675.  *    Function Set_DLOG_Text_Item(), this function sets text boxes in the
  676.  *    selected dialog to the text which is sent to it.
  677.  **********************************************************************/
  678.  
  679. void Set_DLOG_Text_Item(DialogRef the_dialog, short ID, StringPtr the_text)
  680.     {
  681.     
  682.     Handle        the_handle;
  683.     
  684.     Get_Dialog_Item_Hndl(the_dialog, ID, &the_handle);
  685.     SetDialogItemText(the_handle, the_text);
  686.     
  687.     }
  688.  
  689.  
  690.  
  691. /**********************************************************************
  692.  *    Function Draw_Chng_Dialog(), this function draws the objects in the
  693.  *    Change dialog box.
  694.  **********************************************************************/
  695.  
  696. static pascal void Draw_Chng_Dialog(DialogRef the_dialog, short blank_item)
  697.     {
  698.     
  699.     Rect        item_rect;
  700.     GrafPtr        old_port;
  701.     
  702.     GetPort(&old_port);
  703.     SetPort(the_dialog);
  704.     
  705.     if(!Multiple_Files) Draw_Chng_Crnt_Type(the_dialog);
  706.     Draw_Border(the_dialog, CHNG_OK, YES);
  707.     
  708.     SetPort(old_port);
  709.  
  710.     }
  711.     
  712.  
  713.  
  714. /**********************************************************************
  715.  *    Function Draw_Abot_Dialog(), this function draws the objects in the
  716.  *    About dialog box.
  717.  **********************************************************************/
  718.  
  719. static pascal void Draw_Abot_Dialog(DialogRef the_dialog, short blank_item)
  720.     {
  721.     
  722.     GrafPtr        old_port;
  723.     
  724.     GetPort(&old_port);
  725.     SetPort(the_dialog);
  726.     
  727.     Draw_Border(the_dialog, ABOUT_OK, YES);
  728.     
  729.     SetPort(old_port);
  730.     
  731.     }
  732.  
  733.  
  734.  
  735. /**********************************************************************
  736.  *    Function Draw_Pref_Dialog, this function draws the information
  737.  *    in the Prefernces dialog box.
  738.  **********************************************************************/
  739.  
  740. static pascal void Draw_Pref_Dialog(DialogRef the_dialog, short blank_item)
  741.     {
  742.     
  743.     short        i;
  744.     Rect        item_rect;
  745.     GrafPtr        old_port;
  746.     
  747.     Draw_Border(the_dialog, PREF_DONE, YES);
  748.  
  749.     GetPort(&old_port);
  750.     SetPort(the_dialog);
  751.     
  752.     PenSize(1, 1);
  753.     for(i=2;i<=6;i++)
  754.         {
  755.         Get_Dialog_Item_Rect(the_dialog, i, &item_rect);
  756.         FrameRect(&item_rect);
  757.         }
  758.         
  759.     SetPort(old_port);
  760.         
  761.     if(Pref.menu_id==P_GENERL_ITEM) Draw_Pref_Gnrl(the_dialog, NIL_PTR);
  762.     
  763.     }
  764.  
  765.  
  766.  
  767. /**********************************************************************
  768.  *    Function Draw_Pref_Gnrl(), this function draws the objects in the
  769.  *    Preference dialog box with respecto the General DITL.
  770.  **********************************************************************/
  771.  
  772. static pascal void Draw_Pref_Gnrl(DialogRef the_dialog, short blank_item)
  773.     {
  774.     
  775.     Handle        item_handle;
  776.     short        os=Pref.num_items;
  777.     GrafPtr        old_port;
  778.     
  779.     GetPort(&old_port);
  780.     SetPort(the_dialog);
  781.         
  782.     Get_Dialog_Item_Hndl(the_dialog, os+P_GN_OKAC, &item_handle);
  783.     SetControlValue((ControlHandle)item_handle, (**Global).AutoChange);
  784.     Get_Dialog_Item_Hndl(the_dialog, os+P_GN_QADD, &item_handle);
  785.     SetControlValue((ControlHandle)item_handle, (**Global).DragQuit);
  786.     
  787.     SetPort(old_port);
  788.     
  789.     }
  790.  
  791.  
  792.  
  793. /**********************************************************************
  794.  *    Function Handle_Pref_Set_Up_DLOG(), this function  appends the new 
  795.  *    dialog items to the main preference dialog.
  796.  **********************************************************************/
  797.  
  798. void Handle_Pref_Set_Up_DLOG(DialogRef the_dialog, short the_ditl, short *ditl_count)
  799.     {
  800.     
  801.     Handle            ditl_handle;
  802.     
  803.     ditl_handle=GetResource( 'DITL', the_ditl);
  804.     
  805.     HLock(ditl_handle);
  806.     AppendDITL(the_dialog, ditl_handle, overlayDITL);
  807.     HUnlock(ditl_handle);
  808.     ReleaseResource(ditl_handle);
  809.     
  810.     *ditl_count=CountDITL(the_dialog);
  811.     
  812.     }
  813.  
  814.  
  815.  
  816. /**********************************************************************
  817.  *    Function Handle_Pref_Pop_Up_Menu(), this function updates  
  818.  *    and sets up the pop-up menu which decides which dialog
  819.  *    items are displayed.
  820.  **********************************************************************/
  821.  
  822. void Handle_Pref_Pop_Up_Menu(Dialog_Info *the, short first_time)
  823.     {
  824.     
  825.     Handle                    item_handle;
  826.     short                    control_value, num_items;
  827.         
  828.     Get_Dialog_Item_Hndl(the->dialog, PREF_POPUP, &item_handle);
  829.     control_value=GetControlValue((ControlHandle)item_handle);
  830.     if(the->menu_id!=control_value)
  831.         {
  832.         the->menu_id=control_value;
  833.         if(!first_time) ShortenDITL(the->dialog, CountDITL(the->dialog)-PREF_MAX_ITEMS);
  834.         Handle_Pref_Set_Up_DLOG(the->dialog, PREF_DLOG_ID+the->menu_id, &num_items);
  835.         Set_Dialog_Proc((Handle)proc_for_draw_Pref_dialog, the->dialog, num_items);
  836.         switch(control_value)
  837.             {
  838.             case P_EPTYPE_ITEM:
  839.                 Make_Pop_Up_Menu(Edit.menu_id, Edit.pref_type, Edit.num_items);
  840.                 break;
  841.             case P_EATYPE_ITEM:
  842.                 Make_Pop_Up_Menu(Auto.menu_id, Auto.pref_type, Auto.num_items);
  843.                 break;
  844.             }
  845.         }
  846.     
  847.     }
  848.  
  849.  
  850.  
  851. /**********************************************************************
  852.  *    Function Handle_Pref_DITL_Item(), this function ACTUALLY decides where to
  853.  *    to direct an event if it wasn't for the main preference dialog items.
  854.  **********************************************************************/
  855.  
  856. void Handle_Pref_DITL_Item(Dialog_Info *the, short item_hit)
  857.     {
  858.     
  859.     switch(the->menu_id)
  860.         {
  861.         case P_EPTYPE_ITEM:
  862.             Switch_Pt_Dialog(the, item_hit);
  863.             break;
  864.         case P_EATYPE_ITEM:
  865.             Switch_Ac_Dialog(the, item_hit);
  866.             break;
  867.         case P_GENERL_ITEM:
  868.             Switch_Gnrl_Dialog(the, item_hit);
  869.             break;
  870.         }
  871.     
  872.     }
  873.  
  874.  
  875.  
  876. /**********************************************************************
  877.  *    Function Get_Dialog_Text, this function gets text from a dialog
  878.  *    given the dialog and the item to get the text from.
  879.  **********************************************************************/
  880.  
  881. void Get_Dialog_Text(StringPtr the_string, DialogRef the_dialog, short the_item)
  882.     {
  883.     
  884.     Handle        item_handle;
  885.     
  886.     Get_Dialog_Item_Hndl(the_dialog, the_item, &item_handle);
  887.     GetDialogItemText(item_handle, the_string);
  888.         
  889.     }
  890.  
  891.  
  892.  
  893. /**********************************************************************
  894.  *    Function Set_Dialog_Proc(), this function attaches a procedure
  895.  *    to an item in a dialog.
  896.  **********************************************************************/
  897.  
  898. void Set_Dialog_Proc(Handle the_proc, DialogRef the_dialog, short the_item)
  899.     {
  900.     
  901.     Handle        item_handle;
  902.     short        item_type;
  903.     Rect        item_rect;
  904.     
  905.     GetDialogItem(the_dialog, the_item, &item_type, &item_handle, &item_rect);
  906.     SetDialogItem(the_dialog, the_item, item_type, the_proc, &item_rect);
  907.     
  908.     }
  909.  
  910.  
  911.  
  912. /**********************************************************************
  913.  *    Function Get_Dialog_Item_Hndl(), this function gets a handle to 
  914.  *    a dialog item.
  915.  **********************************************************************/
  916.  
  917. void Get_Dialog_Item_Hndl(DialogRef the_dialog, short the_item, Handle *the_handle)
  918.     {
  919.     
  920.     short        item_type;
  921.     Rect        item_rect;
  922.     
  923.     GetDialogItem(the_dialog, the_item, &item_type, the_handle, &item_rect);
  924.     
  925.     }
  926.  
  927.  
  928.  
  929. /**********************************************************************
  930.  *    Function Get_Dialog_Item_Rect(), this function gets the rect for
  931.  *     a dialog item.
  932.  **********************************************************************/
  933.  
  934. void Get_Dialog_Item_Rect(DialogRef the_dialog, short the_item, Rect *the_rect)
  935.     {
  936.     
  937.     Handle        item_handle;
  938.     short        item_type;
  939.     
  940.     GetDialogItem(the_dialog, the_item, &item_type, &item_handle, the_rect);
  941.     
  942.     }
  943.  
  944.  
  945.  
  946. /**********************************************************************
  947.  *    Function Get_Dialog_Item_In_Rect(), this function determines if a 
  948.  *    click was in a certain rect.
  949.  **********************************************************************/
  950.  
  951. Boolean Get_Dialog_Item_In_Rect(DialogRef the_dialog, short the_item, Point the_point)
  952.     {
  953.     
  954.     Rect    item_rect;
  955.     
  956.     Get_Dialog_Item_Rect(the_dialog, the_item, &item_rect);
  957.     if(PtInRect(the_point, &item_rect)) return(YES);
  958.     return(NO);
  959.     
  960.     }
  961.  
  962.  
  963.  
  964. /**********************************************************************
  965.  *    Function Handle_Drag_Tracking(), this function handles the tracking
  966.  *    of the drag over the particular dialog box.
  967.  **********************************************************************/
  968.  
  969. pascal OSErr Handle_Drag_Tracking(short the_message, WindowRef the_dialog, void *handlerRefCon, unsigned long the_drag)
  970.     {
  971.     
  972.     unsigned short        the_count;
  973.     unsigned long        the_attributes;
  974.     short                the_result;
  975.  
  976.     GetDragAttributes(the_drag, &the_attributes);
  977.  
  978.     switch(the_message)
  979.         {
  980.         case dragTrackingEnterHandler:
  981.             break;
  982.         case dragTrackingEnterWindow:
  983.             break;
  984.         case dragTrackingInWindow:
  985.             {
  986.             RgnHandle    the_rgn;
  987.             Point        the_point, the_local_point;
  988.             Rect        the_rect;
  989.             
  990.             GetDragMouse(the_drag, &the_point, NIL_PTR);
  991.             the_local_point=the_point;
  992.             GlobalToLocal(&the_local_point);
  993.             
  994.             if(the_attributes & dragHasLeftSenderWindow)
  995.                 {
  996.                 if(PtInRect(the_local_point, &the_dialog->portRect))
  997.                     {
  998.                     RectRgn(the_rgn=NewRgn(), &the_dialog->portRect);
  999.                     ShowDragHilite(the_drag, the_rgn, true);
  1000.                     DisposeRgn(the_rgn);
  1001.                     }
  1002.                 else HideDragHilite(the_drag);
  1003.                 }
  1004.             }
  1005.             break;
  1006.         case dragTrackingLeaveWindow:
  1007.             HideDragHilite(the_drag);
  1008.             break;
  1009.         case dragTrackingLeaveHandler:
  1010.             break;
  1011.         }
  1012.     return(noErr);    
  1013.     }
  1014.  
  1015.  
  1016.  
  1017. /**********************************************************************
  1018.  *    Function Handle_Drag_Receive_Drop(), this function handles what 
  1019.  *    happens when the drag is dropped on the dialog.
  1020.  **********************************************************************/
  1021.  
  1022. pascal OSErr Handle_Drag_Receive_Drop(WindowRef the_dialog, void *handlerRefCon, unsigned long the_drag)
  1023.     {
  1024.     
  1025.     unsigned short    the_count;
  1026.     ItemReference   the_item;
  1027.     FlavorFlags     the_flags;
  1028.     Str4            the_c_type, the_f_type;
  1029.     HFSFlavor        *the_hfs_flavor;
  1030.     OSType            folder1='fold', disk='disk', folder2='fdrp';
  1031.     Size            the_size;
  1032.     
  1033.     CountDragItems(the_drag, &the_count);
  1034.     
  1035.     if(the_count==1)
  1036.         {
  1037.         GetDragItemReferenceNumber(the_drag, the_count, &the_item);
  1038.         GetFlavorDataSize(the_drag, the_item, flavorTypeHFS, &the_size);
  1039.         the_hfs_flavor=(HFSFlavor *)NewPtr(the_size);
  1040.         GetFlavorData(the_drag, the_item, flavorTypeHFS, the_hfs_flavor, &the_size, NIL_PTR);
  1041.         
  1042.         if( (the_hfs_flavor->fileType!=folder1) && (the_hfs_flavor->fileType!=disk)&& (the_hfs_flavor->fileType!=folder2) )
  1043.             {
  1044.             Set_Type_Text(the_f_type, the_hfs_flavor->fileType);
  1045.             Set_Type_Text(the_c_type, the_hfs_flavor->fileCreator);
  1046.             
  1047.             if(the_dialog==Chng.dialog)
  1048.                 {
  1049.                 Set_DLOG_Text_Item(the_dialog, CHNG_FILE,    the_f_type);
  1050.                 Set_DLOG_Text_Item(the_dialog, CHNG_CREATOR, the_c_type);
  1051.                 }
  1052.             else if(the_dialog==Pref.dialog)
  1053.                 if(Pref.menu_id==P_EPTYPE_ITEM)
  1054.                     {
  1055.                     Set_DLOG_Text_Item(the_dialog, P_PT_CT+PREF_MAX_ITEMS, the_c_type);
  1056.                     Set_DLOG_Text_Item(the_dialog, P_PT_FT+PREF_MAX_ITEMS, the_f_type);
  1057.                     }
  1058.                 else if(Pref.menu_id==P_EATYPE_ITEM)
  1059.                     {
  1060.                     Set_DLOG_Text_Item(the_dialog, P_AC_CHFT+PREF_MAX_ITEMS, the_f_type);
  1061.                     Set_DLOG_Text_Item(the_dialog, P_AC_CTCT+PREF_MAX_ITEMS, the_c_type);
  1062.                     Set_DLOG_Text_Item(the_dialog, P_AC_CTFT+PREF_MAX_ITEMS, the_f_type);
  1063.                     }
  1064.             }
  1065.         DisposePtr((Ptr)the_hfs_flavor);
  1066.         }
  1067.             
  1068.     return(noErr);
  1069.     
  1070.     }